package com.cskaoyan.javase.oop2.encapsulate._1extends._9override._0basic;

/**
 * 例子
 * @since 16:14
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo2 {
    public static void main(String[] args) {
        // 只要创建子类Student对象,前面的引用只决定了访问范围,不能决定执行结果
        Student s = new Student();
        // s.eat();
        // s.sleep();
        s.invokeEatPerson();

        Person p = new Student();
        p.invokeEatPerson();

        // p.eat();
        // 引用限制了访问范围,父类引用是无法访问子类独有成员的
        // p.sleep();

        Person p2 = new Person();
        p2.eat();
        p2.invokeEatPerson();
    }
}

class Person {
    public void eat() {
        System.out.println("吃饭!");
    }

    public void invokeEatPerson() {
        eat();
    }
}

class Student extends Person {
    public void eat() {
        System.out.println("学生吃鸡杂面!");
    }

    public void sleep() {
        System.out.println("在教室里睡觉!");
    }
}